import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.net.*;
import javax.imageio.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.text.html.parser.ParserDelegator;

public class LifeOnMars extends JApplet implements KeyListener, ActionListener{
	//JLabels
	private JLabel[][] tile;
	private JLabel rover;
	private JLabel jet;
	private JLabel statusBar;
	private JLabel jetBar, jetBorder;
	private JLabel gameMessage;
	private JLabel objectiveMessage;
	private JLabel warning, boost;
	//URLs
	private URL rover_move_right_url = getClass().getResource("images/rover_move_right.gif");
	private URL rover_move_left_url = getClass().getResource("images/rover_move_left.gif");
	private URL rover_stop_right_url = getClass().getResource("images/rover_stop_right.gif");
	private URL rover_stop_left_url = getClass().getResource("images/rover_stop_left.gif");
	private URL rover_crash_right_url = getClass().getResource("images/rover_crash_right.gif");
	private URL rover_crash_left_url = getClass().getResource("images/rover_crash_left.gif");
	private URL jet_url = getClass().getResource("images/jet.gif");
	private URL tile_0_url = getClass().getResource("images/tile_0.gif");
	private URL tile_1_url = getClass().getResource("images/tile_1.gif");
	private URL tile_2_url = getClass().getResource("images/tile_2.gif");
	private URL tile_B_url = getClass().getResource("images/tile_B.gif");
	private URL tile_C_url = getClass().getResource("images/tile_C.gif");
	private URL tile_D_url = getClass().getResource("images/tile_D.gif");
	private URL tile_E_url = getClass().getResource("images/tile_E.gif");
	private URL tile_F_url = getClass().getResource("images/tile_F.gif");
	private URL tile_G_url = getClass().getResource("images/tile_G.gif");
	private URL tile_H_url = getClass().getResource("images/tile_H.gif");
	private URL tile_I_url = getClass().getResource("images/tile_I.gif");
	private URL tile_J_url = getClass().getResource("images/tile_J.gif");
	private URL tile_K_url = getClass().getResource("images/tile_K.gif");
	private URL tile_L_url = getClass().getResource("images/tile_L.gif");
//	private URL tile_M_url = getClass().getResource("images/tile_M.gif");
//	private URL tile_N_url = getClass().getResource("images/tile_N.gif");
//	private URL tile_O_url = getClass().getResource("images/tile_O.gif");
//	private URL tile_P_url = getClass().getResource("images/tile_P.gif");
//	private URL tile_Q_url = getClass().getResource("images/tile_Q.gif");
//	private URL tile_R_url = getClass().getResource("images/tile_R.gif");
//	private URL tile_S_url = getClass().getResource("images/tile_S.gif");
//	private URL tile_T_url = getClass().getResource("images/tile_T.gif");
//	private URL tile_U_url = getClass().getResource("images/tile_U.gif");
	private URL tile_V_url = getClass().getResource("images/tile_V.gif");
	private URL tile_W_url = getClass().getResource("images/tile_W.gif");
	private URL tile_X_url = getClass().getResource("images/tile_X.gif");
	private URL warning_url = getClass().getResource("images/warning.gif");
	private URL boost_url = getClass().getResource("images/jet_boost.gif");
	private URL recharge_url = getClass().getResource("images/jet_recharge.gif");
	private URL fatal_url = getClass().getResource("images/fatal_error.gif");
	private URL game_msg_1_url = getClass().getResource("images/game_msg_1.gif");
	private URL game_msg_2_url = getClass().getResource("images/game_msg_2.gif");
	private URL objective_thermoelectric_generator_url = getClass().getResource("images/objective_thermoelectric_generator.gif");
	//ImageIcons
	private ImageIcon rover_move_right_icon = new ImageIcon(rover_move_right_url);
	private ImageIcon rover_move_left_icon = new ImageIcon(rover_move_left_url);
	private ImageIcon rover_stop_right_icon = new ImageIcon(rover_stop_right_url);
	private ImageIcon rover_stop_left_icon = new ImageIcon(rover_stop_left_url);
	private ImageIcon rover_crash_right_icon = new ImageIcon(rover_crash_right_url);
	private ImageIcon rover_crash_left_icon = new ImageIcon(rover_crash_left_url);
	private ImageIcon jet_icon = new ImageIcon(jet_url);
	private ImageIcon tile_0 = new ImageIcon(tile_0_url);
	private ImageIcon tile_1 = new ImageIcon(tile_1_url);
	private ImageIcon tile_2 = new ImageIcon(tile_2_url);
	private ImageIcon tile_B = new ImageIcon(tile_B_url);
	private ImageIcon tile_C = new ImageIcon(tile_C_url);
	private ImageIcon tile_D = new ImageIcon(tile_D_url);
	private ImageIcon tile_E = new ImageIcon(tile_E_url);
	private ImageIcon tile_F = new ImageIcon(tile_F_url);
	private ImageIcon tile_G = new ImageIcon(tile_G_url);
	private ImageIcon tile_H = new ImageIcon(tile_H_url);
	private ImageIcon tile_I = new ImageIcon(tile_I_url);
	private ImageIcon tile_J = new ImageIcon(tile_J_url);
	private ImageIcon tile_K = new ImageIcon(tile_K_url);
	private ImageIcon tile_L = new ImageIcon(tile_L_url);
//	private ImageIcon tile_M = new ImageIcon(tile_M_url);
//	private ImageIcon tile_N = new ImageIcon(tile_N_url);
//	private ImageIcon tile_O = new ImageIcon(tile_O_url);
//	private ImageIcon tile_P = new ImageIcon(tile_P_url);
//	private ImageIcon tile_Q = new ImageIcon(tile_Q_url);
//	private ImageIcon tile_R = new ImageIcon(tile_R_url);
//	private ImageIcon tile_S = new ImageIcon(tile_S_url);
//	private ImageIcon tile_T = new ImageIcon(tile_T_url);
//	private ImageIcon tile_U = new ImageIcon(tile_U_url);
	private ImageIcon tile_V = new ImageIcon(tile_V_url);
	private ImageIcon tile_W = new ImageIcon(tile_W_url);
	private ImageIcon tile_X = new ImageIcon(tile_X_url);
	private ImageIcon warning_icon = new ImageIcon(warning_url);
	private ImageIcon boost_icon = new ImageIcon(boost_url);
	private ImageIcon recharge_icon = new ImageIcon(recharge_url);
	private ImageIcon fatal_icon = new ImageIcon(fatal_url);
	private ImageIcon game_msg_1 = new ImageIcon(game_msg_1_url);
	private ImageIcon game_msg_2 = new ImageIcon(game_msg_2_url);
	private ImageIcon objective_thermoelectric_generator = new ImageIcon(objective_thermoelectric_generator_url);
	//Ints
	int rX, rY;
	int tile0X, tile0Y;
	int xSpeed, ySpeed;
	int jetPower, jetLevel, jetCap, jetRecharge;
	int area;
	int objective_msg_timer;
	int fallCount;
	int save_rX, save_rY, save_area, save_X, save_Y;
	//Booleans
	Boolean leftPressed, rightPressed, upPressed, downPressed;
	Boolean jetOn;
	Boolean onGround;
	Boolean isDead;
		//game objective Booleans
	Boolean landing_wreckage;
	Boolean additional_wreckage;
	Boolean viking_one;
	//Files
	private URL area1 = getClass().getResource("areas/area_1.txt");
	private URL area2 = getClass().getResource("areas/area_2.txt");
	StringBuffer content = new StringBuffer();
	BufferedReader reader;
	//Other Objects
	Container pane = getContentPane();
	JLayeredPane game;
	Timer gameTimer;
	char[][] tileMap = new char[148][77];
	String direction;

	public void init() {
		ParserDelegator workaround = new ParserDelegator();
		game = new JLayeredPane();
		pane.add(game);
		game.setLayout(null);
		game.setOpaque(true);
		game.setBackground(Color.black);
		game.setSize(576,384);
		addKeyListener(this);
		gameTimer = new Timer(60, this);
	}

	public void start(){
	//status bar
		statusBar = new JLabel();
		statusBar.setBounds(0, 336, 560, 32);
		statusBar.setOpaque(true);
		statusBar.setBackground(Color.BLACK);
		statusBar.setBorder(BorderFactory.createLineBorder(Color.white));
		game.add(statusBar);
		game.setLayer(statusBar, 6);
	//jetBar
		jetBar = new JLabel();
		jetBar.setOpaque(true);
		jetBar.setBackground(Color.red);
		game.add(jetBar);
		game.setLayer(jetBar, 8);
	//jeBorder
		jetBorder = new JLabel();
		jetBorder.setBorder(BorderFactory.createLineBorder(Color.white));
		game.add(jetBorder);
		game.setLayer(jetBorder, 7);
	//jet
		jet = new JLabel(jet_icon);
		game.add(jet);
		game.setLayer(jet,5);
	//tiles
		tile = new JLabel[37][23];
		for(int x=0; x<37; x++){
			for(int y=0; y<23; y++){
				tile[x][y] = new JLabel();
				game.add(tile[x][y]);
				game.setLayer(tile[x][y], 2);
			}
		}
	//rover
		rover = new JLabel(rover_move_right_icon);
		game.add(rover);
		game.setLayer(rover, 5);
	//game message
		gameMessage = new JLabel();
		gameMessage.setBorder(BorderFactory.createLineBorder(Color.white));
		game.add(gameMessage);
		game.setLayer(gameMessage, 9);
	//objective message
		objectiveMessage = new JLabel();
		objectiveMessage.setBounds(280, 337, 280, 30);
		game.add(objectiveMessage);
		game.setLayer(objectiveMessage, 10);
	//warning
		warning = new JLabel(warning_icon);
		warning.setBounds(245, 5, 70, 20);
		game.add(warning);
		game.setLayer(warning, 11);
	//boost
		boost = new JLabel(boost_icon);
		boost.setBounds(230, 25, 100, 20);
		game.add(boost);
		game.setLayer(boost, 11);

		resetVars();

		resetLevel();
		gameTimer.start();
	}
//KEY EVENTS
	public void keyPressed(KeyEvent e){
		if(e.getKeyCode()==e.VK_UP){upPressed = true;}
		if(e.getKeyCode()==e.VK_DOWN){downPressed = true;}
		if(e.getKeyCode()==e.VK_LEFT){leftPressed = true;}
		if(e.getKeyCode()==e.VK_RIGHT){rightPressed = true;}
		if(e.getKeyCode()==e.VK_C && isDead){resetLevel();}
	}
	public void keyReleased(KeyEvent e){
		if(e.getKeyCode()==e.VK_UP){upPressed = false; jet.setBounds(0,0,0,0);}
		if(e.getKeyCode()==e.VK_DOWN){downPressed = false;}
		if(e.getKeyCode()==e.VK_LEFT){leftPressed = false;}
		if(e.getKeyCode()==e.VK_RIGHT){rightPressed = false;}
	}
	public void keyTyped(KeyEvent e){ }
//ACTION EVENTS
	public void actionPerformed(ActionEvent e){
		if(e.getSource() == gameTimer){//G A M E  T I M E R XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
			int x=0;
			int y=0;
			if(!leftPressed && !rightPressed){if(xSpeed>0){xSpeed--;}if(xSpeed<0){xSpeed++;}}
			if(leftPressed){xSpeed--; direction = "left";}
			if(rightPressed){xSpeed++; direction = "right";}
			if(upPressed && jetPower>0){
				jetOn=true; onGround=false; jetPower--;
				if(jetPower==0){jetOn=false; jet.setBounds(0,0,0,0);}
				jetBar.setBounds(20, 340, jetPower, 24);
			}else{jetOn = false;}
			if(xSpeed > 4){xSpeed = 4;}
			if(xSpeed <-4){xSpeed =-4;}
			x=xSpeed;
			if(!jetOn){ySpeed++; if(ySpeed>9){ySpeed = 9;}}//how fast can you fall
			if(ySpeed==9){fallCount++; warning.setVisible(true);}else{fallCount = 0; warning.setVisible(false);}
			if(jetOn){ySpeed--;if(ySpeed<-jetLevel){ySpeed=-jetLevel;}}
			y = ySpeed;
			if(x!=0 || y!=0){moveRover();}
			if(jetOn){jet.setBounds(rX, rY+16, 16, 16);}
			if(onGround){
				jetPower=jetPower+jetRecharge;
				if(jetPower>=jetCap){jetPower=jetCap;}
				jetBar.setBounds(20, 340, jetPower, 24);
			}
			if(objective_msg_timer > 0){objective_msg_timer--;}
			if(objective_msg_timer== 1){objectiveMessage.setIcon(null); boost.setVisible(false);}
		}//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
	}
//FUNCTIONS
	public void moveRover(){//MOVE ROVER==========
		checkTiles();
		int x = xSpeed;
		int y = ySpeed;

		int difference;
		rX = rX + x;
		rY = rY + y;
		int shiftX = 0;
		int shiftY = 0;
		if(rX > 430 && tile0X !=111){
			if(rX-x<430){difference = rX - 430;}else{difference = 0;}
			rX = 430;
			shiftX = x-difference;
		}
		if(rX < 130 && tile0X !=0){
			if(rX-x > 130){difference = rX - 130;}else{difference = 0;}
			rX = 130;
			shiftX = x+difference;
		}
		if(rY > 250 && tile0Y!=52 && ySpeed>0){
			if(rY-y < 250){difference = rY - 250;}else{difference = 0;}
			rY = 250;
			shiftY = y-difference;
		}
		if(rY < 100 && tile0Y!=0){
			if(rY-y > 100){difference = rY - 100;}else{difference = 0;}
			rY = 100;
			shiftY = y - difference;
		}
		if(shiftX != 0 || shiftY != 0){
			moveTiles(shiftX, shiftY);
		}
		setRoverIcon();
		rover.setBounds(rX, rY, 16, 16);
		if(rX<-10 || rX>555){
			areaShift();
		}
	}
	public void setRoverIcon(){//SET ROVER ICON==========
		if(xSpeed >0){rover.setIcon(rover_move_right_icon);}
		if(xSpeed <0){rover.setIcon(rover_move_left_icon);}
		if(xSpeed==0 && direction.equals("right")){rover.setIcon(rover_stop_right_icon);}
		if(xSpeed==0 && direction.equals("left")){rover.setIcon(rover_stop_left_icon);}
		if(isDead && direction.equals("left")){rover.setIcon(rover_crash_left_icon);}
		if(isDead && direction.equals("right")){rover.setIcon(rover_crash_right_icon);}
	}
	public void checkTiles(){//CHECK TILES==========
		Rectangle roverBounds = new Rectangle();
		int x = (int)Math.floor(((-16-tile[0][0].getX())+rX+xSpeed)/16d);
		int y = (int)Math.floor(((-16-tile[0][0].getY())+rY+ySpeed)/16d);
		int newX = rover.getX() + xSpeed;
		int newY = rover.getY() + ySpeed;
		Boolean gameMessageOut = false;
		for(int r=0; r<3; r++){
			for(int c=0; c<3; c++){
				int xAdjust, yAdjust;
				xAdjust = x+c;if(xAdjust<0){xAdjust = 0;}if(xAdjust>36){xAdjust = 36;}
				yAdjust = y+r;if(yAdjust<0){yAdjust = 0;}if(yAdjust>22){yAdjust = 21;}
				Object ti = tile[xAdjust][yAdjust].getIcon();//ti = tile icon
				JLabel t = tile[xAdjust][yAdjust];//tb = tile bound
//				tile[x+c][y+r].setBorder(BorderFactory.createLineBorder(Color.white));
				if(ySpeed>0){//down
					roverBounds.setBounds(rover.getX(), newY+16, 16, 1);
					if(roverBounds.getBounds().intersects(t.getBounds()) && (ti!=tile_0 && ti!=tile_1 && ti!=tile_2 && ti!=tile_V && ti!=tile_W && ti!=tile_X)){
						if(fallCount>9){isDead = true; objectiveMessage.setIcon(fatal_icon); gameTimer.stop();}//DEATH
						if(rY!=t.getY()-17){ySpeed = (t.getY()-17)-rY;}else{ySpeed = 0;}
						if(!isDead){onGround = true;}
					}
				}
				if(ySpeed<0){//up
					roverBounds.setBounds(rover.getX(), newY, 16, 1);
					if(roverBounds.getBounds().intersects(t.getBounds()) && (ti!=tile_0 && ti!=tile_1 && ti!=tile_2 && ti!=tile_V && ti!=tile_W && ti!=tile_X)){ySpeed = 0;}
				}
				if(xSpeed<0){//left
					roverBounds.setBounds(newX, rover.getY()+1, 1, 15);
					if(roverBounds.getBounds().intersects(t.getBounds()) && (ti!=tile_0 && ti!=tile_1 && ti!=tile_2 && ti!=tile_V && ti!=tile_W && ti!=tile_X)){xSpeed = 0;}
				}
				if(xSpeed>0){//right
					roverBounds.setBounds(newX+16, rover.getY()+1, 1, 15);
					if(roverBounds.getBounds().intersects(t.getBounds()) && (ti!=tile_0 && ti!=tile_1 && ti!=tile_2 && ti!=tile_V && ti!=tile_W && ti!=tile_X)){xSpeed = 0;}
				}
				if(rover.getBounds().intersects(t.getBounds()) && (ti==tile_W || ti==tile_V || ti==tile_X)){
					displayGameMessage(ti); gameMessageOut = true;
				}
			}
		}
		if(gameMessageOut!=true){gameMessage.setBounds(0,0,0,0);}
	}
	public void moveTiles(int dX, int dY){//MOVE TILES==========
		int xStart = tile[0][0].getX();
		int yStart = tile[0][0].getY();
		int xShift = 0;
		int yShift = 0;
		if(tile[0][0].getX()-dX >= 0){
			int difference = tile[0][0].getX()-dX;
			xStart = -16+difference;
			xShift = -1;
		}
		if(tile[0][0].getX()-dX <=-32){
			int difference = tile[0][0].getX()-dX+32;
			xStart = -16+difference;
			xShift = 1;
		}
		if(tile[0][0].getY()-dY >= 0){
			int difference = tile[0][0].getY()-dY;
			yStart = -16+difference;
			yShift = -1;
		}
		if(tile[0][0].getY()-dY <=-32){
			int difference = tile[0][0].getY()-dY+32;
			yStart = -16+difference;
			yShift = 1;
		}
		if(yShift==0 && xShift==0){
			int pX = tile[0][0].getX() - dX;
			int pY = tile[0][0].getY() - dY;
			int tX, tY;
			for(int y=0; y<23; y++){
				for(int x=0; x<37; x++){
					tX = (pX)+(16*x);
					tY = (pY)+(16*y);
					tile[x][y].setBounds(tX,tY,16,16);
				}
			}
		}else{
			shiftTiles(xStart, yStart, xShift, yShift);
		}
	}
	public void shiftTiles(int xStart, int yStart, int xShift, int yShift){
		//set coordinates
		int pX, pY;
		for(int y=0; y<23; y++){
			for(int x=0; x<37; x++){
				pX = (xStart)+(16*x);
				pY = (yStart)+(16*y);
				tile[x][y].setBounds(pX,pY,16,16);
			}
		}
		//set tile images to character map
		String tileCode;
		int mapX, mapY, mapXStop, mapYStop;
		mapY = tile0Y + yShift;
		mapX = tile0X + xShift;
		mapYStop = mapY + 23;
		mapXStop = mapX + 37;
		int tileY = 0;
		for(int r=mapY; r<mapYStop; r++){
			int tileX = 0;
			for(int c=mapX; c<mapXStop; c++){
				if(tileX==0 && tileY==0){tile0X = mapX; tile0Y = mapY;}
				tileCode = Character.toString(tileMap[c][r]);
				if(tileCode.equals("0")){tile[tileX][tileY].setIcon(tile_0);}
				if(tileCode.equals("1")){tile[tileX][tileY].setIcon(tile_1);}
				if(tileCode.equals("2")){tile[tileX][tileY].setIcon(tile_2);}
				if(tileCode.equals("B")){tile[tileX][tileY].setIcon(tile_B);}
				if(tileCode.equals("C")){tile[tileX][tileY].setIcon(tile_C);}
				if(tileCode.equals("D")){tile[tileX][tileY].setIcon(tile_D);}
				if(tileCode.equals("E")){tile[tileX][tileY].setIcon(tile_E);}
				if(tileCode.equals("F")){tile[tileX][tileY].setIcon(tile_F);}
				if(tileCode.equals("G")){tile[tileX][tileY].setIcon(tile_G);}
				if(tileCode.equals("H")){tile[tileX][tileY].setIcon(tile_H);}
				if(tileCode.equals("I")){tile[tileX][tileY].setIcon(tile_I);}
				if(tileCode.equals("J")){tile[tileX][tileY].setIcon(tile_J);}
				if(tileCode.equals("K")){tile[tileX][tileY].setIcon(tile_K);}
				if(tileCode.equals("L")){tile[tileX][tileY].setIcon(tile_L);}
				if(tileCode.equals("V")){tile[tileX][tileY].setIcon(tile_V);}
				if(tileCode.equals("W")){tile[tileX][tileY].setIcon(tile_W);}
				if(tileCode.equals("X")){tile[tileX][tileY].setIcon(tile_X);}
				tileX++;
			}
			tileY++;
		}
	}

	public void setTiles(int xStart, int yStart){//SET TILES==========
		//set coordinates
		int pX, pY;
		for(int y=0; y<23; y++){
			for(int x=0; x<37; x++){
				pX = (-16)+(16*x);
				pY = (-16)+(16*y);
				tile[x][y].setBounds(pX,pY,16,16);
			}
		}
		//set tile images to character map
		String tileCode;
		int mapX, mapY;
		mapY = yStart;
		int mapYStop = mapY + 23;
		int tileY = 0;
		while(mapY<mapYStop){
			mapX = xStart;
			int mapXStop = mapX + 37;
			int tileX = 0;
			while(mapX<mapXStop){
				if(tileX==0 && tileY==0){tile0X = mapX; tile0Y = mapY;}
				tileCode = Character.toString(tileMap[mapX][mapY]);
				if(tileCode.equals("0")){tile[tileX][tileY].setIcon(tile_0);}
				if(tileCode.equals("1")){tile[tileX][tileY].setIcon(tile_1);}
				if(tileCode.equals("2")){tile[tileX][tileY].setIcon(tile_2);}
				if(tileCode.equals("B")){tile[tileX][tileY].setIcon(tile_B);}
				if(tileCode.equals("C")){tile[tileX][tileY].setIcon(tile_C);}
				if(tileCode.equals("D")){tile[tileX][tileY].setIcon(tile_D);}
				if(tileCode.equals("E")){tile[tileX][tileY].setIcon(tile_E);}
				if(tileCode.equals("F")){tile[tileX][tileY].setIcon(tile_F);}
				if(tileCode.equals("G")){tile[tileX][tileY].setIcon(tile_G);}
				if(tileCode.equals("H")){tile[tileX][tileY].setIcon(tile_H);}
				if(tileCode.equals("I")){tile[tileX][tileY].setIcon(tile_I);}
				if(tileCode.equals("J")){tile[tileX][tileY].setIcon(tile_J);}
				if(tileCode.equals("K")){tile[tileX][tileY].setIcon(tile_K);}
				if(tileCode.equals("L")){tile[tileX][tileY].setIcon(tile_L);}
				if(tileCode.equals("V")){tile[tileX][tileY].setIcon(tile_V);}
				if(tileCode.equals("W")){tile[tileX][tileY].setIcon(tile_W);}
				if(tileCode.equals("X")){tile[tileX][tileY].setIcon(tile_X);}
				mapX++; tileX++;
			}
			mapY++; tileY++;
		}
	}
	public void setMap(URL area){//SET MAP==========
		String[] line = new String [76];
		//set icons
		try{
			reader = new BufferedReader(new InputStreamReader(area.openStream()));
			int i = 0;
			while ((line[i] = reader.readLine()) != null){i++;}
		}
		catch(FileNotFoundException e){System.out.println("area file not found");}
		catch(IOException e){e.printStackTrace();}
		finally{
			try{if(reader!=null){reader.close();}}
			catch(IOException e){e.printStackTrace();}
		}
		//set tile map
		int l = 0;
		while(l<75){
			int c = 0;
			while(c<line[l].length()){
				tileMap[c][l] = line[l].charAt(c);
				c++;
			}
			l++;
		}
	}
	public void areaShift(){// ========== AREA SHIFT ==========
		if(area==1 && rX< -10){
			area = 2;
			setMap(area2);
			setTiles(111,tile0Y);
			rX = 550;
			setCheckPoint();
		}
		if(area==2 && rX> 555){
			area = 1;
			setMap(area1);
			setTiles(0,tile0Y);
			rX = -5;
			setCheckPoint();
		}
		jetOn = false;
		onGround = false;
		xSpeed = 0;
		ySpeed = 0;
		fallCount = 0;
		objectiveMessage.setIcon(null);
		objective_msg_timer = 0;
		warning.setVisible(false);
		boost.setVisible(false);
		isDead = false;
	}
	public void displayGameMessage(Object theIcon){// ========== DISPLAY GAME MESSAGE ==========
		if(area==1 && theIcon==tile_W){gameMessage.setIcon(game_msg_1); gameMessage.setBounds(rX-90, rY-150, 200, 80); if(!landing_wreckage){gameObjectiveMet("landing wreckage");}}
		if(area==1 && theIcon==tile_X){gameMessage.setIcon(game_msg_2); gameMessage.setBounds(rX-90, rY-150, 200, 80); if(!additional_wreckage){gameObjectiveMet("additional wreckage");}}
		if(area==2 && theIcon==tile_V){if(!viking_one){gameObjectiveMet("viking one");}}
	}
	public void gameObjectiveMet(String objective){// ========== GAME OBJECTIVE MET ==========
		if(objective.equals("landing wreckage")){//landing wreckage
			objectiveMessage.setIcon(objective_thermoelectric_generator);
			landing_wreckage = true;
			objective_msg_timer = 80;
			jetCap = jetCap + 10;
			jetPower = jetCap;
			jetBorder.setBounds(19, 339, jetCap+2, 26);
			jetBar.setBounds(20, 340, jetPower, 24);
			boost.setVisible(true);
			setCheckPoint();
		}
		if(objective.equals("additional wreckage")){//additional wreckage
			objectiveMessage.setIcon(objective_thermoelectric_generator);
			additional_wreckage = true;
			objective_msg_timer = 80;
			jetCap = jetCap + 10;
			jetPower = jetCap;
			jetBorder.setBounds(19, 339, jetCap+2, 26);
			jetBar.setBounds(20, 340, jetPower, 24);
			boost.setIcon(boost_icon);
			boost.setVisible(true);
			setCheckPoint();
		}
		if(objective.equals("viking one")){//viking one
			viking_one = true;
			objective_msg_timer = 80;
			jetRecharge = 4;
			boost.setIcon(recharge_icon);
			boost.setVisible(true);
			setCheckPoint();
		}
	}
	public void setCheckPoint(){
		save_rX = rX;
		save_rY = rY;
		save_area = area;
		save_X = tile0X;
		save_Y = tile0Y;
	}
	public void resetLevel(){
		rX = save_rX;
		rY = save_rY;
		rover.setBounds(rX, rY, 16, 16);
		if(save_area==1){setMap(area1);}
		if(save_area==2){setMap(area2);}
		setTiles(save_X, save_Y);
		leftPressed = false; rightPressed = false; upPressed = false; downPressed = false;
		jetOn = false;
		onGround = false;
		xSpeed = 0;
		ySpeed = 0;
		direction = "right";
		jetPower = jetCap;
		fallCount = 0;
		objectiveMessage.setIcon(null);
		objective_msg_timer = 0;
		warning.setVisible(false);
		boost.setVisible(false);
		isDead = false;
		gameTimer.start();
	}
	public void resetVars(){//RESET VARS==========
		//reset game objecives
		landing_wreckage = false;
		additional_wreckage = false;
		viking_one = false;
		jetCap = 40;
		jetPower = jetCap;
		jetLevel = 2;
		jetRecharge = 2;
		jetBorder.setBounds(19, 339, jetCap+2, 26);
		jetBar.setBounds(20, 340, jetPower, 24);
		area = 1;
		//checkpoint zero
		save_rX = 400;
		save_rY = 210;
		save_area = 1;
		save_X = 93;
		save_Y = 28;
	}
}